/*
 * 增加一个新飞机类型须知
 * 如果是固定翼加入到planeList,多旋翼rotorList,垂直起降vtolList
 * 如果是dji设备加入到djiDeviceList中
 * 深圳研发D200，V100系列等采用新飞控协议的，加入到newProtocolList
 */

export enum PlaneTypes {
  F1000 = 'F1000',
  F2000 = 'F2000',
  F200 = 'F200',
  F300 = 'F300',
  P300 = 'P300',
  D20 = 'D20',
  D200 = 'D200',
  D300 = 'D300',
  D500 = 'D500',
  D1000 = 'D1000',
  D2000 = 'D2000',
  E2000 = 'E2000',
  Phantom4 = 'Phantom4',
  Inspire2 = 'Inspire2',
  Mavic2 = 'Mavic2',
  V10 = 'V10',
  V100 = 'V100',
  V200 = 'V200',
  V300 = 'V300',
  V1000 = 'V1000',
  unknow = 'unknow',
}

enum RotorTypes {
  D200 = 'D200',
  D300 = 'D300',
  D1000 = 'D1000',
  Phantom4 = 'Phantom4',
  Inspire2 = 'Inspire2',
  Mavic2 = 'Mavic2',
  D2000 = 'D2000',
  E2000 = 'E2000',
  D500 = 'D500',
  V10 = 'V10',
}
enum FixedTypes {
  F1000 = 'F1000',
  F2000 = 'F2000',
  F200 = 'F200',
  F300 = 'F300',
  P300 = 'P300',
}
enum VtorTypes {
  V100 = 'V100',
  V200 = 'V200',
  V300 = 'V300',
  V1000 = 'V1000',
}
enum NewProtocols {
  D200 = 'D200',
  D300 = 'D300',
  D500 = 'D500',
  V10 = 'V10',
  V100 = 'V100',
  V200 = 'V200',
  V300 = 'V300',
  D2000 = 'D2000',
  V1000 = 'V1000',
  E2000 = 'E2000',
}
export const planeM = {
  //sysMap页面飞机渲染图
  planeModels: {
    F1000: 'F1000.glb',
    F2000: 'F2000.glb',
    F200: 'F200.glb',
    F300: 'F300.glb',
    P300: 'F300.glb',
    D20: 'D20.glb',
    D200: 'D200.glb',
    D300: 'D200.glb',
    D500: 'D500.glb',
    D1000: 'Phantom4.glb',
    D2000: 'D2000.glb',
    E2000: 'D2000.glb',
    Phantom4: 'Phantom4.glb',
    Inspire2: 'mavic.glb',
    Mavic2: 'mavic.glb',
    V10: 'V10.glb',
    V100: 'V100.glb',
    V200: 'V100.glb',
    V300: 'V100.glb',
    V1000: 'V1000.glb',
    unknow: 'mavic.glb',
  },
  djiDeviceList: ['Phantom4', 'Inspire2', 'Mavic2', 'D1000'],
  planeList: ['F1000', 'F2000', 'F200', 'F300', 'P300'],
  rotorList: ['D200', 'D300', 'D1000', 'Phantom4', 'Inspire2', 'Mavic2', 'D2000', 'E2000', 'D500', 'V10'],
  vtolList: ['V100', 'V200', 'V300', 'V1000'],
  //D200新协议支持机型
  newProtocolList: ['D200', 'D300', 'D500', 'V10', 'V100', 'V200', 'V300', 'D2000', 'V1000', 'E2000'],
  findPlane: function (str: string) {
    if (str) {
      str = str.toUpperCase();
      if (str.indexOf('PHANTOM') >= 0) {
        return 'Phantom4';
      }

      if (str.indexOf('INSPIRE') >= 0) {
        return 'Inspire2';
      }

      if (str.indexOf('MAVIC') >= 0) {
        return 'Mavic2';
      }
      const modelsHaveOwnPics = [
        'F1000',
        'F2000',
        'F200',
        'F300',
        'P300',
        'D20',
        'D200',
        'D300',
        'D500',
        'D1000',
        'D2000',
        'E2000',
        'V100',
        'V200',
        'V300',
        'V1000',
        'V10',
      ];
      if (modelsHaveOwnPics.includes(str)) {
        return str;
      }
    }
    return 'unknow';
  },
  //获取飞机图标
  getPlaneModel: function (str: string): string {
    var plane = this.findPlane(str);
    return `/earthmap/res/GroundVehicle/${this.planeModels[plane as PlaneTypes]}`;
  },
  //是否是DJI设备
  isDjiDevice: function (str: string) {
    var plane = this.findPlane(str);
    return this.djiDeviceList.indexOf(plane) >= 0;
  },
  //是否是旋翼飞机
  isRotorDevice: function (str: string) {
    var plane = this.findPlane(str);
    return this.rotorList.indexOf(plane) >= 0;
  },
  //是否是固定翼飞机
  isPlaneDevice: function (str: string) {
    var plane = this.findPlane(str);
    return this.planeList.indexOf(plane) >= 0;
  },
  isNewProtocolDevice: function (str: string) {
    var plane = this.findPlane(str);
    return this.newProtocolList.indexOf(plane) >= 0;
  },
  //不同的飞机，电池个数不同
  getBatteryNumOfPlane(planeType: string): number {
    let num = 1;
    switch (planeType) {
      case PlaneTypes.D200:
      case PlaneTypes.D300:
        num = 3;
        break;

      case PlaneTypes.V100:
      case PlaneTypes.V200:
      case PlaneTypes.V300:
      case PlaneTypes.D500:
        num = 2;
        break;

      case PlaneTypes.D20:
        num = 6;
        break;

      case PlaneTypes.D2000:
      case PlaneTypes.E2000:
      case PlaneTypes.V1000:
      case PlaneTypes.D1000:
        num = 1;
        break;

      case PlaneTypes.V10:
        num = 10;
        break;

      default:
        num = 1;
        break;
    }

    return num;
  },
};
